package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class mapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map=new HashMap<>();
        map.put("english",90);
        map.put("math",96);
        map.put("chinese",95);
        map.put("chenistry",95);
        System.out.println(map);
        Set<String> set=map.keySet();
        for(String key:set){
            System.out.println("key:"+key);
        }
        set.forEach(new Consumer<String>() {//1
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        set.forEach(s-> System.out.println(s));//2
        set.forEach(System.out::println);//3
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String k, Integer v) {
                System.out.println(k+":"+v);
            }
        });
        map.forEach((k,v)-> System.out.println(k+":"+v));

        Set<Map.Entry<String,Integer>> entrySet=map.entrySet();
        for (Map.Entry<String,Integer> e:entrySet){
            String key=e.getKey();
            Integer value= e.getValue();
            System.out.println(key+":"+value);
        }

        Collection<Integer> values=map.values();
        for (Integer value :values){
            System.out.println("value:"+value);
        }
    }
}
